package com.mike.mvcframework.pojo;

import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @Description 封装handler方法相关参数
 * @Date 2021/7/23 8:00
 * @Created by mike
 */
public class Handler {
    private Object controller;
    private Method method;
    private Pattern pattern; // url的正则
    private Map<String,Integer> paramIndexMapping;  // 参数顺序,为了进行参数绑定
    private Set<String> securityList;  // 权限校验列表

    public Handler() {
        this.paramIndexMapping = new HashMap<>();
        this.securityList = new HashSet<>();
    }

    public Handler(Object controller, Method method, Pattern pattern, Map<String, Integer> paramIndexMapping, Set<String> securityList) {
        this.controller = controller;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = paramIndexMapping;
        this.securityList = securityList;
    }

    public Handler(Object controller, Method method, Pattern pattern) {
        this.controller = controller;
        this.method = method;
        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>();
        this.securityList = new HashSet<>();
    }

    @Override
    public String toString() {
        return "Handler{" +
                "controller=" + controller +
                ", method=" + method +
                ", pattern=" + pattern +
                ", paramIndexMapping=" + paramIndexMapping +
                ", securityList=" + securityList +
                '}';
    }

    public Set<String> getSecurityList() {
        return securityList;
    }

    public void setSecurityList(Set<String> securityList) {
        this.securityList = securityList;
    }

    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Map<String, Integer> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Integer> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }
}
